home *** CD-ROM | disk | FTP | other *** search
- <?xml version="1.0" encoding="utf-8"?>
- <!-- ===========================================================
- Styelsheet: SubstringDDMMYYYY.xsl
- Category: FilteringSorting
- Sub-category: DateSorting using Substring
- Author: David Silverlight
- HeadGeek@xmlpitstop.com
- Created: 2001-05-16
- Description:-
- This stylsheet demonstrates how to use the substring
- function to sort a date. In this example, we are using a
- 3 part sort key for month, day and year. Since we are
- breaking it into 3 sections, we can easily control the order
- (ascending or descending) for each part of our date. In this
- example, we are sorting by Day, Month, Year
- ================================================================ -->
- <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
- <xsl:output method="html" encoding="ISO-8859-1" doctype-public="-//W3C//DTD HTML 4.0 Transitional//EN" />
-
- <xsl:template match="/">
- <html>
- <head>
- <title>FilteringSorting - DateSorting using Substring</title>
- <style type="text/css">
- H1 {COLOR: red; FONT-FAMILY: Arial; FONT-SIZE: 14pt;}
- H2 {COLOR: darkblue; FONT-FAMILY: Arial; FONT-SIZE: 12pt;}
- .head {COLOR: darkblue; FONT-FAMILY: Arial; FONT-SIZE: 14pt;}
- .subhead {COLOR: darkblue; FONT-FAMILY: Arial; FONT-SIZE: 12pt;}
- .text {COLOR: black; FONT-FAMILY: Arial; FONT-SIZE: 12pt;}
- TH {COLOR: white; FONT-FAMILY: Arial; background-color: darkblue;}
- TD {COLOR: darkblue; FONT-FAMILY: Arial}
- TR { background-color: beige; }
- BODY { background-color: beige; }
- </style>
- </head>
- <body>
- <h1>Display of transactions in order of Day, Month, Year (DDMMYYYY)</h1>
- <span class="subhead">Start Dates</span>
- <table border="1">
- <tr>
- <th>Transaction Start Date</th>
- <th>Description</th>
- <th>Day</th>
- <th>Month</th>
- <th>Year</th>
- </tr>
- <xsl:for-each select="/transactions/transaction">
- <xsl:sort order="ascending" select="substring(@startdate, 9,2)" />
- <xsl:sort order="ascending" select="substring(@startdate, 6,2)" />
- <xsl:sort order="ascending" select="substring(@startdate, 1,4)" />
- <tr>
- <td>
- <xsl:value-of select="@startdate" />
- </td>
- <td>
- <xsl:value-of select="@description" />
- </td>
- <td>
- <xsl:value-of select="substring(@startdate, 9,2)" />
- </td>
- <td>
- <xsl:value-of select="substring(@startdate, 6,2)" />
- </td>
- <td>
- <xsl:value-of select="substring(@startdate, 1,4)" />
- </td>
- </tr>
- </xsl:for-each>
- </table>
- <br />
- <br />
- <span class="subhead">End Dates</span>
- <table border="1">
- <tr>
- <th>Transaction End Date</th>
- <th>Description</th>
- <th>Day</th>
- <th>Month</th>
- <th>Year</th>
- </tr>
- <xsl:for-each select="/transactions/transaction">
- <xsl:sort order="ascending" select="substring(@enddate, 9,2)" />
- <xsl:sort order="ascending" select="substring(@enddate, 6,2)" />
- <xsl:sort order="ascending" select="substring(@enddate, 1,4)" />
- <tr>
- <td>
- <xsl:value-of select="@enddate" />
- </td>
- <td>
- <xsl:value-of select="@description" />
- </td>
- <td>
- <xsl:value-of select="substring(@enddate, 9,2)" />
- </td>
- <td>
- <xsl:value-of select="substring(@enddate, 6,2)" />
- </td>
- <td>
- <xsl:value-of select="substring(@enddate, 1,4)" />
- </td>
- </tr>
- </xsl:for-each>
- </table>
- </body>
- </html>
- </xsl:template>
- </xsl:stylesheet>
-